package com.itcsystem.manager;

import com.itcsystem.connection.ConnectionUtility;
import java.util.ArrayList;
import java.util.List;
import java.sql.*;
import com.itcsystem.struct.Alumno;

public class AlumnoManager{
	private ConnectionUtility connectionUtility = ConnectionUtility.getConnectionUtility();

	public Integer insertAlumno(Alumno alumno){
		String sql = "INSERTALUMNO ?,?,?,?";
	
		List<Object> parameters = new ArrayList<Object>();
		parameters.add(alumno.getNombre());
		parameters.add(alumno.getPlanestudios());
	
		parameters.add(alumno.getGeneracion());
		connectionUtility.buildPreparedStatement(sql, parameters, true);
		
		return connectionUtility.executeSQLInsert();
	}
	public Boolean deleteAlumno(int idAlumno){
		String sql = "DELETEALUMNO ?";
		connectionUtility.buildPreparedStatement(sql, idAlumno);
	
		return connectionUtility.executeSQLDelete();
	}
	public List<Alumno> getAlumnos(){
		List<Alumno> listAlumno = new ArrayList<Alumno>();
		String sql = "SELECTALUMNO";
	
		try{
			ResultSet resultSet = connectionUtility.getResult(sql);
		
			if (resultSet !=null){
				while(resultSet.next()){
					Alumno obj = new Alumno();
		
					obj.setNumeroControl((int)resultSet.getObject("NumeroControl"));
	
					obj.setNombre((java.lang.String)resultSet.getObject("Nombre"));
	
					obj.setPlanestudios((int)resultSet.getObject("Planestudios"));
	
					obj.setGeneracion((int)resultSet.getObject("Generacion"));
					
					listAlumno.add(obj);
				}
			}
		}
		catch(SQLException ex){
			ex.printStackTrace();
		}
	
		return listAlumno;
	}
}
